/**
 * @class   wosh::automations::CronJob
 * @brief   
 *

 *
 * @see     wosh::automations::Automation
 ****************************************************************************
 * @version 0.8.013 $Id: CronJob.h 2863 2010-08-07 04:28:58Z alex $Id: CronJob.h 2037 2010-03-05 15:04:52Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Automations_CronJob_H__
 #define __WOSH_Automations_CronJob_H__

 #include <framework/automations/Automation.h>
 

namespace wosh {
 namespace automations {

 #define _CronJob_VERSION				0.12

 #define _CronJob_KEY_year				"year"
 #define _CronJob_KEY_month				"month"
 #define _CronJob_KEY_day				"day"
 #define _CronJob_KEY_hour				"hour"
 #define _CronJob_KEY_min				"min"
 #define _CronJob_KEY_sec				"sec"

 #define _CronJob_KEY_NextInterrupt		"NextInterrupt"

class CronJob : public Automation
 {
	WOSH_SERIALIZABLE(wosh::automations::CronJob)
	WOSH_COMPARE_RTTI(wosh::automations::CronJob)


	public:
		/**
		 * @brief  Empty constructor.
		 */
		CronJob();
		/**
		 * @brief  Copy constructor.
		 * @param m [in] the source object to be copied
		 */
		CronJob( const CronJob& m );
		/**
		 * @brief  Empty destructor.
		 */
		virtual ~CronJob();


	public:
		virtual WRESULT init();
		virtual WRESULT deinit();

		virtual WRESULT execute( const Message* trigger_message, const MessageFilter* trigger_filter );

//@}
/** @name Setters
 * @{
 ******************************************************************************/
	public:
		void setDate( int year, int month, int day );
		void setTime( int hour, int min, int sec );

		void setYear( int value )					{ this->year = value; updatedTime(); }
		void setMonth( int value )					{ this->month = value; updatedTime(); }
		void setDay( int value )					{ this->day = value; updatedTime(); }
		void setHour( int value )					{ this->hour = value; updatedTime(); }
		void setMin( int value )					{ this->min = value; updatedTime(); }
		void setSec( int value )					{ this->sec = value; updatedTime(); }

//@}
/** @name Getters
 * @{
 ******************************************************************************/
	public:
		std::string getDate() const;
		std::string getTime() const;

		inline int getYear() const					{ return this->year; }
		inline int getMonth() const					{ return this->month; }
		inline int getDay() const					{ return this->day; }
		inline int getHour() const					{ return this->hour; }
		inline int getMin() const					{ return this->min; }
		inline int getSec() const					{ return this->sec; }

		inline bool isYearly() const				{ return (this->year == -1); }
		inline bool isMonthly() const				{ return (this->month == -1); }
		// week
		inline bool isDaily() const					{ return (this->day == -1); }
		inline bool isHourly() const				{ return (this->hour == -1); }
		inline bool isMinutely() const				{ return (this->min == -1); }

//@}
/** @name IPropertiesProviderListener interface
 * @{
 ******************************************************************************/
 	public:
		virtual bool updatingProperty( bool& doUpdate, const Variant& value_proposed, Property& property_current, const PropertiesProvider* source );
//@}
/** @name Operators Overloading
 * @{
 ******************************************************************************/
	public:
		CronJob& operator=(const CronJob& m);
		bool operator==(const CronJob &other) const;
//@}
/** @name Serialization interface
 * @{
 ******************************************************************************/
	public:
		virtual bool updateHash( DataHashContext* hash_context ) const;
//@}
	protected:
		void schedulerControl( bool enable );
		void updatedTime( bool schedule_commit = false );
		virtual void clear();

	protected:
		int64 nextInterrupt;
		int year; 			///< 
		int month;			///< 0->11
		int day; 			///< 1-31
		int hour; 			///< 0-23
		int min; 			///< 0-59
		int sec; 			///< 0-59


}; // class def

 }; // namespace automations
}; // namespace wosh

#endif //__WOSH_Automations_CronJob_H__
